import type { FcPageConfig } from '@/types/fcform'
import { createColums } from './table/columns.ts'
import { createSearchForm } from './search/index.ts'
import { createFormItems } from './editItem/formItems.ts'
import { createRules } from './editItem/rules.ts'

import { createFormItems as createClassifyFormItem } from './edit/formItems.ts'
import { createRules as createClassifyRules } from './edit/rules.ts'

export function usePageConfig(): FcPageConfig {
  return {
    KEY: 'id',
    pageProps: {
      createSearchForm,
      tools: {
        add: {
          auth: 'sys_dict_add',
        },
        del: false,
      },
    },
    table: {
      getApi: '/admin/dict/item/page',
      delApi: {
        api: '/admin/dict/item',
        method: 'delete',
        path: true,
      },
      initForm: {
        ascs: 'sort_order',
      },
      createColums,
    },
    edit: {
      default: {
        addApi: '/admin/dict/item',
        editApi: {
          api: '/admin/dict/item',
          method: 'put',
        },
        defaultValue: {
          dictType: null,
          label: '',
          value: '',
          itemValue: '',
          description: '',
          sortOrder: 1,
          remarks: '',
        },
        createItems: createFormItems,
        createRule: createRules,
      },
      classify: {
        addApi: '/admin/dict',
        editApi: {
          api: '/admin/dict',
          method: 'put',
        },
        defaultValue: {
          dictType: '',
          systemFlag: '1',
          description: '',
          remarks: '',
        },
        createItems: createClassifyFormItem,
        createRule: createClassifyRules,
      },
    },
  }
}
